package com.chinanet.repository.faultanticipate.manager;


import com.chinanet.entry.faultanticipate.manager.Rolle;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RestResource;

public interface RolleRepository extends PagingAndSortingRepository<Rolle, Long>{
    @RestResource(path = "team", rel = "team")
    @Query(value = "select * from rolle r left join rolle_teams r_t on r_t.rolles_id=r.id left join team t on r_t.teams_id = t.id where t.id=:teamId", nativeQuery = true)
    Page<Rolle> getAllByTeam(@Param("teamId") long teamId, Pageable pageable);

    @RestResource(path = "notTeam", rel = "not/team")
    @Query(value = "select * from rolle r left join rolle_teams r_t on r_t.rolles_id=r.id left join team t on r_t.teams_id = t.id where r_t.rolles_id not in (select r_t.rolles_id from rolle_teams r_t where r_t.teams_id =:teamId )or t.id is null group by role_name", nativeQuery = true)
    Page<Rolle> getAllNotByTeam(@Param("teamId") long teamId, Pageable pageable);
}